import React, { useState } from 'react';
import useMyReducer from '../reducer';
import {useNavigate} from 'react-router-dom'
const Index = () => {
    const navigate =useNavigate() 
    const [state,dispatch] =useMyReducer()
    const [citys] =useState(["西安","上海","重庆","厦门","杭州"])
    const handleCity =(val)=>{
        dispatch({
            type:"changeCity",
            value:val
        })
        navigate(-1)
    }
    return (
        <div>
            {citys.map(item=>{
                return (  
                <button key={item} onClick={()=>handleCity(item)}>{item}</button>
                   
                    )
            })}
        </div>
    );
}

export default Index;
